package com.sand.controller;

import com.sand.dto.Owner.MerchantOrOwner;
import com.sand.dto.Owner.SchemeAdd;
import com.sand.dto.Owner.SchemeSelectById;
import com.sand.dto.Owner.schemeUpdate;
import com.sand.entity.buy.scheme;
import com.sand.result.ResponseResult;
import com.sand.service.SchemeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/scheme")
public class SchemeController {

    @Autowired
    private SchemeService schemeService;


    /**
     *客户添加方案
     */
    @PostMapping("/add")
    public ResponseResult<String> add(@RequestBody SchemeAdd schemeAdd){

        String i = schemeService.addOrUpdate(schemeAdd);

        return new ResponseResult<String>().ok(i);
    }

    /**
     *客户,商家查看所有方案
     */
    @PostMapping("/getById")
    public ResponseResult<List<scheme>> getByid(@RequestBody MerchantOrOwner merchantOrOwner){
         List<scheme> list = schemeService.getByid(merchantOrOwner);
         return new ResponseResult<List<scheme>>().ok(list);
    }



    /**
     * 客户,商家修改方案
     */
    @PostMapping("/update")
    public ResponseResult<String> upd(@RequestBody schemeUpdate schemeUpdate){
        String i = schemeService.upd(schemeUpdate);
        return new ResponseResult<String>().ok(i);
    }


    /**
     *方案确认
     */
    @PostMapping("/ok")
    public ResponseResult<Integer> ok(@RequestBody Integer id){
        Integer i = schemeService.ok(id);
        return new ResponseResult<Integer>().ok(i);
    }



    /**
     * 商家或客户根据id获取方案
     */
    @PostMapping("/getid")
    public ResponseResult<scheme> getid(@RequestBody SchemeSelectById schemeSelectById){

        scheme scheme = schemeService.getid(schemeSelectById);

        return new ResponseResult<scheme>().okResult(scheme,"查询成功");
    }


    /**
     *客户删除方案
     */
    @PostMapping("/down")
    public ResponseResult<Integer> down(@RequestBody Integer id){
        Integer i = schemeService.down(id);
        return new ResponseResult<Integer>().ok(i);
    }


    /**
     * 查康方案详细
     */

}
